package com.dgut.common.util;

import java.util.List;

import javax.servlet.http.HttpSession;

import com.dgut.usermodule.entity.User;

public class SessionUtil 
{
	public static final String USER 		= "user";
	public static final String USERNAME 	= "userName";
	
    /**
     * 设置用户到session
     */
    public static void setUser(HttpSession session, User user) {
        session.setAttribute(USER, user);
        setUserName(session,user.getUserName());
    }

    /**
     * 从Session获取当前用户信息
     */
    public static User getUser(HttpSession session) {
        Object user = session.getAttribute(USER);
        return user == null ? null : (User) user;
    }

    /**
     * 设置用户到session
     */
    public static void setUserName(HttpSession session, String userName) {
        session.setAttribute(USERNAME, userName);
    }

    /**
     * 从Session获取当前用户信息
     */
    public static String getUserName(HttpSession session) {
        Object userName = session.getAttribute(USERNAME);
        return userName == null ? null : (String) userName;
    }
    
	
	
	public static void removeAttribute(HttpSession session) {
		session.removeAttribute(USER);
		session.removeAttribute(USERNAME);
    }
    
}
